

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
    <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="lynx">
  <meta name="keywords" content="">
  
    <meta name="description" content="Github Action 介绍 GitHub Actions 是 GitHub 于 2018 年 10 月推出的持续集成服务。 GitHub Actions 的工作原理如下：  当我们设置好需要自动化执行的任务脚本（存放在 .github&#x2F;workflows​ 目录下的 .yml​ 文件）后，GitHub Actions 监控当前仓库的某一个操作（如 push）。 一旦有此操作发生，GitHub">
<meta property="og:type" content="article">
<meta property="og:title" content="在 GitHub Pages 上自动部署 Hexo">
<meta property="og:url" content="https://l0223.github.io.git/2024/04/05/%E5%9C%A8%20GitHub%20Pages%20%E4%B8%8A%E8%87%AA%E5%8A%A8%E9%83%A8%E7%BD%B2%20Hexo/index.html">
<meta property="og:site_name" content="Lynx&#39;s Blog">
<meta property="og:description" content="Github Action 介绍 GitHub Actions 是 GitHub 于 2018 年 10 月推出的持续集成服务。 GitHub Actions 的工作原理如下：  当我们设置好需要自动化执行的任务脚本（存放在 .github&#x2F;workflows​ 目录下的 .yml​ 文件）后，GitHub Actions 监控当前仓库的某一个操作（如 push）。 一旦有此操作发生，GitHub">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://picoflynx.oss-cn-guangzhou.aliyuncs.com/source/images/gallery/%E6%96%87%E7%AB%A0%E5%9B%BE/202404062119199.png">
<meta property="article:published_time" content="2024-04-05T23:17:19.000Z">
<meta property="article:modified_time" content="2024-04-08T09:34:59.670Z">
<meta property="article:author" content="Yeahill Lin">
<meta property="article:tag" content="网页搭建">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://picoflynx.oss-cn-guangzhou.aliyuncs.com/source/images/gallery/%E6%96%87%E7%AB%A0%E5%9B%BE/202404062119199.png">
  
  
  
  <title>在 GitHub Pages 上自动部署 Hexo - Lynx&#39;s Blog</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  



  
<link rel="stylesheet" custom_css="&#x2F;css&#x2F;fold_code,&#x2F;css&#x2F;iconfont_fold&#x2F;iconfont.css" href="/.css">



  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"l0223.github.io.git","root":"/","version":"1.9.7","typing":{"enable":true,"typeSpeed":50,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":{"measurement_id":null},"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml","include_content_in_search":true};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 7.1.1"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>Lynx&#39;s Blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/" target="_self">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/" target="_self">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/category/" target="_self">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/" target="_self">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/photos/" target="_self">
                <i class="iconfont icon-image"></i>
                <span>photos</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/" target="_self">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('https://picoflynx.oss-cn-guangzhou.aliyuncs.com/source/images/gallery/%E6%96%87%E7%AB%A0%E5%9B%BE/202404062119199.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="在 GitHub Pages 上自动部署 Hexo"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        lynx
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2024-04-05 23:17" pubdate>
          2024年4月5日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          1.4k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          12 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <h1 id="seo-header">在 GitHub Pages 上自动部署 Hexo</h1>
            
            
              <div class="markdown-body">
                
                <h1>Github Action 介绍</h1>
<p>GitHub Actions 是 GitHub 于 2018 年 10 月推出的持续集成服务。</p>
<p>GitHub Actions 的工作原理如下：</p>
<ol>
<li>当我们设置好需要自动化执行的任务脚本（存放在 <code>.github/workflows</code>​ 目录下的 <code>.yml</code>​ 文件）后，GitHub Actions 监控当前仓库的某一个操作（如 push）。</li>
<li>一旦有此操作发生，GitHub Actions 将分配一个虚拟主机来自动化执行这些任务。</li>
</ol>
<p>我们设置的任务即为 Action，它存放在项目根目录的 <code>.github/workflows</code>​ 文件下，后缀为 <code>.yml</code>​。一个 Action 相当于是一个工作流，一个工作流可以包含多个任务，每个任务又可以分成几个步骤。任务、步骤会依次执行。</p>
<p><strong>接下来就是操作步骤了</strong></p>
<h1>1、Hexo 本地源文件连接 github page 仓库</h1>
<ol>
<li>
<p><strong>GitHub 上建立名为</strong>  <code>**&lt;你的 GitHub 用户名&gt;.github.io**</code> <strong>的储存库</strong>，若之前已将 Hexo 上传至其他储存库，将该储存库重命名即可。教程参考 👉<a href="siyuan://blocks/20240403225625-rs9ss7g">siyuan://blocks/20240403225625-rs9ss7g</a></p>
</li>
<li>
<p>**git 创建新分支（若本地还未连接过 github 仓库，可参考：**​<a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_29493173/article/details/113094143">Github——git 本地仓库建立与远程连接（最详细清晰版本！附简化步骤与常见错误）_将本地仓库与远程仓库关联-CSDN 博客</a>）</p>
<figure class="highlight plaintext"><i class="iconfont icon-github-fill" type="button" data-toggle="collapse" data-target="#collapse-gum6ktluqrb9fe"></i><span>git</span><div class="collapse show" id="collapse-gum6ktluqrb9fe"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs git">git branch new-branch #本地创建一个新的分支，new-branch为新分支名<br><br>git checkout new-branch #切换到新分支<br><br>#如果你已经在本地进行了一些修改（例如，添加了新文件或者修改了现有文件），你需要将这些更改暂存并提交到新分支上<br>git add . #将更改暂存<br><br>git commit -m &quot;Your commit message&quot; #使用git commit命令将暂存的更改提交到新分支上<br><br>git push origin new-branch #将新分支的更改推送到远程仓库<br></code></pre></td></tr></table></div></figure>
</li>
<li>
<p>将 Hexo 文件夹中的文件 push 到储存库新建的非默认分支（如 hexooo）</p>
</li>
</ol>
<ul>
<li>
<p>将本地 hexooo 分支 push 到 GitHub</p>
<figure class="highlight maxima"><i class="iconfont icon-github-fill" type="button" data-toggle="collapse" data-target="#collapse-fw1bloluqrb9fe"></i><span>maxima</span><div class="collapse show" id="collapse-fw1bloluqrb9fe"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs maxima">git <span class="hljs-built_in">push</span> -u <span class="hljs-built_in">origin</span> hexooo<br></code></pre></td></tr></table></div></figure>
</li>
<li>
<p>默认情况下 <code>public/</code>​ 不会被上传(也不该被上传)，确保 <code>.gitignore</code>​ 文件中包含一行 <code>public/</code>​。整体文件夹结构应该与 <a target="_blank" rel="noopener" href="https://github.com/hexojs/hexo-starter">示例储存库</a> 大致相似。</p>
</li>
</ul>
<h1>2、配置密钥</h1>
<p>如果你的 Hexo 可以正常地部署到 GitHub，那么实际上你原来的秘钥是可以正常使用的。但是私钥可能还用于不同的服务器的 SSH 访问和其他身份验证，因此，我们生成一个新的秘钥对来专门部署 Hexo。</p>
<p>以操作系统是 Windows 为例：</p>
<ol>
<li>
<p><strong>打开命令提示符</strong>：在开始菜单中搜索并打开 “命令提示符&quot;或&quot;cmd”。</p>
</li>
<li>
<p><strong>检查是否已存在 SSH 密钥</strong>：输入以下命令并按 Enter 键：</p>
<figure class="highlight bash"><i class="iconfont icon-github-fill" type="button" data-toggle="collapse" data-target="#collapse-6mm10mluqrb9fe"></i><span>bash</span><div class="collapse show" id="collapse-6mm10mluqrb9fe"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-built_in">dir</span> %userprofile%\.ssh<br></code></pre></td></tr></table></div></figure>
<p>如果已经存在 SSH 密钥，你将看到类似 <code>id_rsa</code>​ 和 <code>id_rsa.pub</code>​ 这样的文件。这些文件就是你的 SSH 私钥和公钥。</p>
</li>
<li>
<p><strong>如果没有 SSH 密钥，生成新的密钥</strong>：输入以下命令并按 Enter 键：</p>
<figure class="highlight bash"><i class="iconfont icon-github-fill" type="button" data-toggle="collapse" data-target="#collapse-0uplk7luqrb9fe"></i><span>bash</span><div class="collapse show" id="collapse-0uplk7luqrb9fe"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">ssh-keygen -t rsa -b 4096 -C <span class="hljs-string">&quot;your_email@example.com&quot;</span><br></code></pre></td></tr></table></div></figure>
<p>替换 <code>your_email@example.com</code>​ 为你的 GitHub 注册邮箱。这条命令将会生成一对新的 SSH 密钥。</p>
</li>
<li>
<p><strong>按提示操作</strong>：运行上述命令后，你会看到一些提示，如密钥文件的保存位置等。你可以选择默认选项，或者按照提示输入自定义的文件名和密码。</p>
</li>
<li>
<p><strong>添加 SSH 密钥到 GitHub</strong>：完成密钥生成后，你需要将<strong>公钥</strong>（一般是以 XXXpub 结尾的）和私钥都添加到 GitHub 上。你可以使用命令来显示，也可以去刚刚生成密钥文件查看。</p>
</li>
<li>
<p><strong>在 GitHub 上添加公钥</strong>：在 GitHub 部署仓库，进入 Settings -&gt; Deploy keys -&gt; Add deploy key 页面。在 “Title” 中输入一个描述性的标题如，然后粘贴刚才复制的公钥到 “Key” 文本框中，最后点击 “Add SSH key” 按钮。</p>
<p><img src="https://picoflynx.oss-cn-guangzhou.aliyuncs.com/source/images/siyuanpic/20240405222023.png" srcset="/img/loading.gif" lazyload alt="image.png" title="Deploy keys页面"></p>
</li>
<li>
<p><strong>在 GitHub 上添加部署 Action 私钥：</strong> 仓库访问 Settings -&gt; Deploy keys -&gt; New respository secret，名字部分填写：<code>HEXO_DEPLOY_KEY</code>​，注意大小写，这个后面的 GitHub Actions Workflow 要用到，一定不能写错。</p>
<p><img src="https://picoflynx.oss-cn-guangzhou.aliyuncs.com/source/images/siyuanpic/20240405222337.png" srcset="/img/loading.gif" lazyload alt="image.png" title="Action secret页面"></p>
</li>
</ol>
<h1>3、创建 Github Action 工作流 workflow</h1>
<ul>
<li>使用 <code>node --version</code>​ 指令检查你电脑上的 Node.js 版本，并<strong>记下该版本</strong> (例如：<code>v20.y.z</code>​)</li>
<li>在 github 储存库中前往 <code>Settings &gt; Pages &gt; Source</code>​，并将 <code>Source</code>​ 改为 <code>GitHub Actions</code>​。</li>
<li>在本地 Hexo 根目录中创建 <code>.github/workflows/pages.yml</code>​，并填入以下内容 (将 node 版本中的 20 替换为第一个步骤中记下的版本)：</li>
</ul>
<figure class="highlight yml"><i class="iconfont icon-github-fill" type="button" data-toggle="collapse" data-target="#collapse-nld6urluqrb9fe"></i><span>yml</span><div class="collapse show" id="collapse-nld6urluqrb9fe"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br></pre></td><td class="code"><pre><code class="hljs yml"><span class="hljs-comment"># 定义一个名为 Pages 的动作</span><br><span class="hljs-attr">name:</span> <span class="hljs-string">Pages</span><br><br><span class="hljs-comment"># 当有一个新的推送（push）到名为 hexooo 的分支时，执行部署任务</span><br><span class="hljs-attr">on:</span><br>  <span class="hljs-attr">push:</span><br>    <span class="hljs-attr">branches:</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-string">hexooo</span><br><br><span class="hljs-comment"># 定义一个名为 build-and-deploy 的 job</span><br><span class="hljs-attr">jobs:</span><br>  <span class="hljs-attr">build-and-deploy:</span><br>    <span class="hljs-comment"># 在 Ubuntu 最新版本上运行此 job</span><br>    <span class="hljs-attr">runs-on:</span> <span class="hljs-string">ubuntu-latest</span><br>    <span class="hljs-attr">steps:</span><br>      <span class="hljs-comment"># 检出 hexooo 分支的代码</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Checkout</span> <span class="hljs-string">code</span> <span class="hljs-string">from</span> <span class="hljs-string">hexooo</span> <span class="hljs-string">branch</span><br>        <span class="hljs-attr">uses:</span> <span class="hljs-string">actions/checkout@v4</span><br>        <span class="hljs-attr">with:</span><br>          <span class="hljs-attr">ref:</span> <span class="hljs-string">hexooo</span><br>          <span class="hljs-attr">persist-credentials:</span> <span class="hljs-literal">false</span><br><br>      <span class="hljs-comment"># 设置 Git 用户信息</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Set</span> <span class="hljs-string">up</span> <span class="hljs-string">Git</span> <span class="hljs-string">user</span> <span class="hljs-string">information</span><br>        <span class="hljs-attr">run:</span> <span class="hljs-string">|</span><br><span class="hljs-string">          git config --global user.name &quot;XXX&quot;</span><br><span class="hljs-string">          git config --global user.email &quot;XXX@XXX.com&quot;</span><br><span class="hljs-string"></span><br>      <span class="hljs-comment"># 设置 Node.js 20.x 版本</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Set</span> <span class="hljs-string">up</span> <span class="hljs-string">Node.js</span> <span class="hljs-number">20.</span><span class="hljs-string">x</span><br>        <span class="hljs-attr">uses:</span> <span class="hljs-string">actions/setup-node@v2</span><br>        <span class="hljs-attr">with:</span><br>          <span class="hljs-attr">node-version:</span> <span class="hljs-string">&#x27;20&#x27;</span><br>  <br>      <span class="hljs-comment"># 全局安装 Hexo</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Install</span> <span class="hljs-string">Hexo</span> <span class="hljs-string">globally</span><br>        <span class="hljs-attr">run:</span> <span class="hljs-string">|</span><br><span class="hljs-string">          npm install -g hexo-cli</span><br><span class="hljs-string">          npm install</span><br><span class="hljs-string"></span><br>      <span class="hljs-comment"># 缓存 NPM 依赖</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Cache</span> <span class="hljs-string">NPM</span> <span class="hljs-string">dependencies</span><br>        <span class="hljs-attr">uses:</span> <span class="hljs-string">actions/cache@v2</span><br>        <span class="hljs-attr">with:</span><br>          <span class="hljs-attr">path:</span> <span class="hljs-string">node_modules</span><br>          <span class="hljs-attr">key:</span> <span class="hljs-string">$&#123;&#123;</span> <span class="hljs-string">runner.OS</span> <span class="hljs-string">&#125;&#125;-node-$&#123;&#123;</span> <span class="hljs-string">hashFiles(&#x27;**/package-lock.json&#x27;)</span> <span class="hljs-string">&#125;&#125;</span><br>          <span class="hljs-attr">restore-keys:</span> <span class="hljs-string">|</span><br><span class="hljs-string">            $&#123;&#123; runner.OS &#125;&#125;-node-</span><br><span class="hljs-string"></span><br>      <span class="hljs-comment"># 使用环境变量 ACTION_DEPLOY_KEY 部署到主分支</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Deploy</span> <span class="hljs-string">to</span> <span class="hljs-string">main</span> <span class="hljs-string">branch</span><br>        <span class="hljs-attr">env:</span><br>          <span class="hljs-attr">ACTION_DEPLOY_KEY:</span> <span class="hljs-string">$&#123;&#123;</span> <span class="hljs-string">secrets.HEXO_DEPLOY_KEY</span> <span class="hljs-string">&#125;&#125;</span><br>        <span class="hljs-attr">run:</span> <span class="hljs-string">|</span><br><span class="hljs-string">          mkdir -p ~/.ssh/</span><br><span class="hljs-string">          echo &quot;$ACTION_DEPLOY_KEY&quot; &gt; ~/.ssh/id_rsa</span><br><span class="hljs-string">          chmod 700 ~/.ssh</span><br><span class="hljs-string">          chmod 600 ~/.ssh/id_rsa</span><br><span class="hljs-string">          ssh-keyscan github.com &gt;&gt; ~/.ssh/known_hosts</span><br><span class="hljs-string"></span><br>      <span class="hljs-comment"># 部署</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Deploy</span><br>        <span class="hljs-attr">run:</span> <span class="hljs-string">|</span><br><span class="hljs-string">          hexo clean</span><br><span class="hljs-string">          hexo generate</span><br><span class="hljs-string">          hexo deploy</span><br></code></pre></td></tr></table></div></figure>
<ol start="6">
<li>
<p>文件创建完后，push 至 github，在仓库页面的 Action 选项卡可查看工作部署流程</p>
<p><img src="https://picoflynx.oss-cn-guangzhou.aliyuncs.com/source/images/siyuanpic/20240405230309.png" srcset="/img/loading.gif" lazyload alt="image.png" title="Action部署页面"></p>
</li>
</ol>
<p>最后，前往 <code>https://&lt;你的 GitHub 用户名&gt;.github.io</code>​ 查看网站</p>
<p><img src="https://picoflynx.oss-cn-guangzhou.aliyuncs.com/source/images/siyuanpic/20240405230721.png" srcset="/img/loading.gif" lazyload alt="image.png" title="部署成功"></p>
<h2 id="参考链接">参考链接</h2>
<ul>
<li><a target="_blank" rel="noopener" href="https://docs.github.com/zh/pages">GitHub Pages 使用文档</a></li>
<li><a target="_blank" rel="noopener" href="https://docs.github.com/zh/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#%E4%BD%BF%E7%94%A8%E8%87%AA%E5%AE%9A%E4%B9%89-github-actions-%E5%B7%A5%E4%BD%9C%E6%B5%81%E8%BF%9B%E8%A1%8C%E5%8F%91%E5%B8%83">使用自定义 GitHub Actions 工作流进行发布</a></li>
<li><a target="_blank" rel="noopener" href="https://github.com/marketplace/actions/deploy-github-pages-site">actions/deploy-github-pages-site</a></li>
<li><a target="_blank" rel="noopener" href="https://hexo.io/zh-cn/docs/github-pages">在 GitHub Pages 上部署 Hexo | Hexo</a></li>
<li><a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_29493173/article/details/113094143">Github——git 本地仓库建立与远程连接（最详细清晰版本！附简化步骤与常见错误）_将本地仓库与远程仓库关联-CSDN 博客</a></li>
<li><a target="_blank" rel="noopener" href="https://zhuanlan.zhihu.com/p/170563000">GitHub Actions 来自动部署 Hexo - 知乎 (zhihu.com)</a></li>
<li><a target="_blank" rel="noopener" href="https://zhuanlan.zhihu.com/p/161969042#:~:text=%E4%BD%BF%E7%94%A8%20GitHub%20Actions%20%E8%87%AA%E5%8A%A8%E9%83%A8%E7%BD%B2%20Hexo%20%E5%8D%9A%E5%AE%A2%E5%88%B0%20GitHub%20Pages,%E5%BC%80%E5%8F%91%E6%BA%90%E7%A0%81%E3%80%82%20...%203%20%E9%83%A8%E7%BD%B2%20%E6%9C%80%E5%90%8E%EF%BC%8C%E6%88%91%E4%BB%AC%E5%8F%AA%E9%9C%80%E8%A6%81%E5%B0%86%E6%BA%90%E7%A0%81%E6%8E%A8%E9%80%81%E5%88%B0%E6%8C%87%E5%AE%9A%E5%88%86%E6%94%AF%EF%BC%8CGitHub%20Actions%20%E5%B0%B1%E4%BC%9A%E8%87%AA%E5%8A%A8%E5%B8%AE%E6%88%91%E4%BB%AC%E9%83%A8%E7%BD%B2%E9%A1%B9%E7%9B%AE%E5%95%A6%E3%80%82%20">使用 GitHub Actions 自动部署 Hexo 博客到 GitHub Pages - 知乎 (zhihu.com)</a></li>
</ul>
<p>‍</p>
<link rel="stylesheet" href="/css/spoiler.css" type="text/css"><script src="/js/spoiler.js" type="text/javascript" async></script>
                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E7%94%9F%E4%BA%A7%E6%8C%87%E5%8D%97/" class="category-chain-item">生产指南</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/%E7%BD%91%E9%A1%B5%E6%90%AD%E5%BB%BA/" class="print-no-link">#网页搭建</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>在 GitHub Pages 上自动部署 Hexo</div>
      <div>https://l0223.github.io.git/2024/04/05/在 GitHub Pages 上自动部署 Hexo/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>lynx</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2024年4月5日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2024/04/07/Hexo%E7%BD%91%E9%A1%B5%E6%90%AD%E5%BB%BA%E8%AE%B0%E5%BD%95%EF%BC%88%E4%B8%80%EF%BC%89/" title="Hexo网页搭建记录（一）">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Hexo网页搭建记录（一）</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2024/03/26/%E5%AF%BB%E6%89%BE%E4%BA%BA%E7%94%9F%E4%B9%8B%E8%B7%AF/" title="《如何找到想做的事》">
                        <span class="hidden-mobile">《如何找到想做的事》</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments" lazyload>
      

    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.4/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.20.1/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
